package src.javaStudy.Thread.createThreadType;

/**
 * @program: AlgorithmTest
 * @description: 数字增加
 *
 * 继承Threa创建线程
 *
 * @author: powerWriter
 * @create: 2019-06-28 09:52
 **/
public class SumCount {
    static double x = 0;

    public static void main(String[] args) {
        Thread T1 = new Thread(new Thre1());//创建线程
        Thread T2 = new Thread(new Thre2());//创建线程
        new Thread(T1).start();//开启线程

        new Thread(T2).start();//开启线程
    }

    public static class Thre1 extends Thread {

        public void run(){//run方法，里面包含需要执行的任务
            while(true){
                try {
                    Thread.sleep(1000);	//使得线程休息时间300ms
                    x+=1.0;
                    System.out.println("+1= "+x);//输出当前数值
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
            }
        }
    }
    public static class Thre2 extends Thread{
        public void run(){//run方法，里面包含需要执行的任务
            while(true){
                try {
                    Thread.sleep(2000);	//使得线程休息时间400ms
                    x+=0.1;
                    System.out.println("+0.1= "+x);//输出当前数值
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
            }
        }
    }
}
